﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessLogic;
using System.Text;

namespace Interface.UserControls
{
    public partial class Slider : System.Web.UI.UserControl
    {
        DataConnection dc = new DataConnection();
        protected void Page_Load(object sender, EventArgs e)
        {
            loadSmallItem();
            loadMainItem();
        }

        protected void loadSmallItem()
        {
            string sql = "Select TOP 4 * from Post Order By PostDate DESC";
            DataTable dt = dc.getData(sql);
            StringBuilder strBuilder1 = new StringBuilder();           
            if (dt.Rows.Count > 0)
            {
                for(int i = 0; i<dt.Rows.Count;i++)
                {
                    DataRow row = dt.Rows[i];                    
                    string title = row["Title"].ToString();
                    string image = row["ImageSource"].ToString();                    
                    strBuilder1.AppendFormat(@"<li class='ui-tabs-nav-item' id='nav-fragment-{0}'>
                                                <a href='#fragment-{0}'>
                                                    <img src='Images/Post/{1}' height='50px' width='80px'/>
                                                    <span>{2}</span>
                                                </a>
                                            </li>", i, image, title);
                    lit1.Text = strBuilder1.ToString();                    
                }
            }

        }

        protected void loadMainItem()
        {
            string sql = "Select TOP 4 * from Post Order By PostDate DESC";
            DataTable dt = dc.getData(sql);            
            StringBuilder strBuilder2 = new StringBuilder();
            if (dt.Rows.Count > 0)
            {
                
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow row = dt.Rows[i];
                    
                    string title = row["Title"].ToString();
                    string image = row["ImageSource"].ToString();
                    string shortDes = row["ShortDescript"].ToString();                    

                    strBuilder2.AppendFormat(@"<div id='fragment-{0}' class='ui-tabs-panel'>
			                                    <img src='Images/Post/{1}' alt="" height='256px' width='314px'/>
			                                     <div class='info'>
				                                    <h2><a href='#'>{2}</a></h2>
				                                    <p>{3}<a href='#' >read more</a></p>
			                                     </div>
	                                        </div>", i, image, title, shortDes);
                    lit2.Text = strBuilder2.ToString();
                }
            }

        }
    }
}